/*
 * 薪资总览
 */
var url = '', jsonData = '';
$(function(){
	loadData();
});

function loadData(){
	loadTopCSS();
	/**
	 * 薪资总览
	 */
	loadPayOverview();
	 
}

function loadTopCSS() {
	$("#li10").addClass("navdown");
}

function loadPayOverview() {
	url = ctx + '/employeeDimissionController/departmentWages';
	
	var departmentId = $('#departmentId').val();
	var startTime = $('#startPayOverview').val();
	var endTime = $('#endPayOverview').val();
	var mycars=new Array();
	mycars[0]="Saab";
	mycars[1]="Volvo";
	mycars[2]="BMW";
//	var mycars = [2,5,7];
	if (startTime.length==0||endTime.length==0||startTime==endTime) {
		
		var date = new Date();
		var year = date.getFullYear();
		var month = date.getMonth()+1;
		var day = date.getDate();
		
		var startYear = year-1;
		
		startTime = startYear+"-"+month;
		endTime = year+"-"+month;
		
	}
	
	$('#startPayOverview').val(startTime);
	$('#endPayOverview').val(endTime);
	
	var pageNum = "0";
	jsonData = {departmentId:departmentId,startTime:startTime,endTime:endTime,pageNum:pageNum,mycars:mycars};
	
	var returnData= commonAjax();
	tbodyHtml = initPayOverviewHtml(returnData.data);
	
	$('#PayOverview_tbody').html(tbodyHtml);
	
	
	/*
	 * 分页数据设置
	 */
	$('#previousPayOverviewInput').val(returnData.prePage);
	$('#nextPayOverviewInput').val(returnData.nextPage);
	$('#lastPayOverviewInput').val(returnData.lastPage);
	
	$('#curPagePayOverview').html(returnData.curPage+1);
	$('#totalNumberPayOverview').html(returnData.totalNumber);
	$('#totalPagePayOverview').html(returnData.totalPage);
	$('#pageSizePayOverview').html(returnData.pageSize);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstPayOverview').attr("disabled","disabled");
		$('#previousPayOverview').attr("disabled","disabled");
	}else {
		$('#firstPayOverview').removeAttr("disabled");
		$('#previousPayOverview').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextPayOverview').attr("disabled","disabled");
		$('#lastPayOverview').attr("disabled","disabled");
	}else {
		$('#nextPayOverview').removeAttr("disabled");
		$('#lastPayOverview').removeAttr("disabled");
	}
	
};

function initPayOverviewHtml(data){
	var returnHtml = '';
	
	if (data.length == 0)
		returnHtml = '<tr><td colspan="5">暂无数据</td></tr>';
	else
		$.each(data, function(index, item) {

			returnHtml += "<tr>"
					+ "<td style='text-align: center' title='" + item.depName + "'>" + item.depName + "</td>"
					+ "<td title='" + item.depNum + "'>"+item.depNum+"</td>" 
					+ "<td title='" + item.salaryTotal + "'>" + item.salaryTotal+ "</td>" 
					+ "<td title='" + item.salaryAve + "'>"+ item.salaryAve + "</td>" 
					+ "<td title='" + item.socialSecurityBenefitsCostTotal + "'>"+ item.socialSecurityBenefitsCostTotal + "</td>"
					+ "<td title='" + item.humanResourceCost + "'>"+ item.humanResourceCost + "</td></tr>";
		});

	
	return returnHtml;
}


/**
 * 部门薪资总览 分页功能-----------------------------------
 */
/*
 * 部门薪资总览    首页按钮
 */
function firstPayOverview(){
	url = ctx + '/employeeDimissionController/departmentWages';
	
	var departmentId = $('#departmentId').val();
	var startTime = $('#startPayOverview').html();
	var endTime = $('#endPayOverview').html();
	var pageNum=0;
	jsonData = {departmentId:departmentId,startTime:startTime,endTime:endTime,pageNum:pageNum};
	var  returnData= commonAjax();
	
	tbodyHtml = initPayOverviewHtml(returnData.data);
	$('#PayOverview_tbody').html(tbodyHtml);
	
	/*
	 * 设置 上下页的隐藏域  值
	 */
	$('#previousPayOverviewInput').val(returnData.prePage);
	$('#nextPayOverviewInput').val(returnData.nextPage);
	
	$('#curPagePayOverview').html(returnData.curPage+1);
	$('#totalNumberPayOverview').html(returnData.totalNumber);
	$('#totalPagePayOverview').html(returnData.totalPage);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstPayOverview').attr("disabled","disabled");
		$('#previousPayOverview').attr("disabled","disabled");
	}else {
		$('#firstPayOverview').removeAttr("disabled");
		$('#previousPayOverview').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextPayOverview').attr("disabled","disabled");
		$('#lastPayOverview').attr("disabled","disabled");
	}else {
		$('#nextPayOverview').removeAttr("disabled");
		$('#lastPayOverview').removeAttr("disabled");
	}
}

/*
 *  部门薪资总览 分页功能    上一页按钮
 */
function previousPayOverview(){
	url = ctx + '/employeeDimissionController/departmentWages';
	
	var departmentId = $('#departmentId').val();
	
	var pageNum= $('#previousPayOverviewInput').val();
	
	var startTime = $('#startPayOverview').html();
	var endTime = $('#endPayOverview').html();
	
	jsonData = {departmentId:departmentId,startTime:startTime,endTime:endTime,pageNum:pageNum};

	var  returnData= commonAjax();
	
	tbodyHtml = initPayOverviewHtml(returnData.data);
	$('#PayOverview_tbody').html(tbodyHtml);
	
	/*
	 * 设置 上下页的隐藏域  值
	 */
	$('#previousPayOverviewInput').val(returnData.prePage);
	$('#nextPayOverviewInput').val(returnData.nextPage);
	
	$('#curPagePayOverview').html(returnData.curPage+1);
	$('#totalNumberPayOverview').html(returnData.totalNumber);
	$('#totalPagePayOverview').html(returnData.totalPage);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstPayOverview').attr("disabled","disabled");
		$('#previousPayOverview').attr("disabled","disabled");
	}else {
		$('#firstPayOverview').removeAttr("disabled");
		$('#previousPayOverview').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextPayOverview').attr("disabled","disabled");
		$('#lastPayOverview').attr("disabled","disabled");
	}else {
		$('#nextPayOverview').removeAttr("disabled");
		$('#lastPayOverview').removeAttr("disabled");
	}
	
}

/*
 *  部门薪资总览 分页功能    下一页按钮
 */
function nextPayOverview(){
	url = ctx + '/employeeDimissionController/departmentWages';
	
	var departmentId = $('#departmentId').val();
	
	var pageNum= $('#nextPayOverviewInput').val();
	var startTime = $('#startPayOverview').html();
	var endTime = $('#endPayOverview').html();
	
	jsonData = {departmentId:departmentId,startTime:startTime,endTime:endTime,pageNum:pageNum};
	
	var  returnData= commonAjax();
	
	tbodyHtml = initPayOverviewHtml(returnData.data);
	$('#PayOverview_tbody').html(tbodyHtml);
	
	/*
	 * 设置 上下页的隐藏域  值
	 */
	$('#previousPayOverviewInput').val(returnData.prePage);
	$('#nextPayOverviewInput').val(returnData.nextPage);
	
	$('#curPagePayOverview').html(returnData.curPage+1);
	$('#totalNumberPayOverview').html(returnData.totalNumber);
	$('#totalPagePayOverview').html(returnData.totalPage);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstPayOverview').attr("disabled","disabled");
		$('#previousPayOverview').attr("disabled","disabled");
	}else {
		$('#firstPayOverview').removeAttr("disabled");
		$('#previousPayOverview').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextPayOverview').attr("disabled","disabled");
		$('#lastPayOverview').attr("disabled","disabled");
	}else {
		$('#nextPayOverview').removeAttr("disabled");
		$('#lastPayOverview').removeAttr("disabled");
	}
	
}

/*
 *  部门薪资总览 分页功能   尾页按钮
 */
function lastPayOverview(){
	url = ctx + '/employeeDimissionController/departmentWages';
	
	var departmentId = $('#departmentId').val();
	
	var pageNum= $('#nextPayOverviewInput').val();
	var startTime = $('#startPayOverview').html();
	var endTime = $('#endPayOverview').html();
	
	jsonData = {departmentId:departmentId,startTime:startTime,endTime:endTime,pageNum:pageNum};
	var  returnData= commonAjax();
	
	tbodyHtml = initPayOverviewHtml(returnData.data);
	$('#PayOverview_tbody').html(tbodyHtml);
	
	/*
	 * 设置 上下页的隐藏域  值
	 */
	$('#previousPayOverviewInput').val(returnData.prePage);
	$('#nextPayOverviewnInput').val(returnData.nextPage);
	
	$('#curPagePayOverview').html(returnData.curPage+1);
	$('#totalNumberPayOverview').html(returnData.totalNumber);
	$('#totalPagePayOverview').html(returnData.totalPage);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstPayOverview').attr("disabled","disabled");
		$('#previousPayOverview').attr("disabled","disabled");
	}else {
		$('#firstPayOverview').removeAttr("disabled");
		$('#previousPayOverview').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextPayOverview').attr("disabled","disabled");
		$('#lastPayOverview').attr("disabled","disabled");
	}else {
		$('#nextPayOverview').removeAttr("disabled");
		$('#lastPayOverview').removeAttr("disabled");
	}
	
}

function commonAjax(){
	var result = '';
	$.ajax({
		type: 'POST',
		data: jsonData,
	    url: url,
	    async: false,
	    dataType:"json",
	    success: function(data){
	    	result = data;
	    },
	    error: function(){
	    }
	});
	return result;
}
/**
 *  ！！！！！！！！！！！异步请求！！！！！！！！！！！！！
 */
/*function commonAjax(fun, dataType){
	$.ajax({
		type: 'POST',
		data: jsonData,
	    url: url,
	    dataType: dataType,
	    success: function(data){
	    	fun(data);
	    },
	    error: function(){
	    }
	});
}*/